<template>
	<view class="formbox">
		<view class="justify-center flex-col align-center"
			style="border-bottom: 1rpx solid #D7DDDC;padding-bottom: 24rpx;">
			<view class="title " style="">
				<span
					style="font-weight: 800;font-size: 40rpx;color: #303B39;z-index: 99;position: relative;">{{title}}</span>
				<view class="pos-abs titleline">
				</view>
			</view>
			<view class="" style="font-size: 28rpx;color: #576260;margin-top: 24rpx;">
				提交您的相关信息，耐心等到药队长医药顾问联系。
			</view>
		</view>
		<view class="formcontent">
			<view class="" style="font-weight: 600;font-size: 32rpx;color: #576260;">
				称呼
			</view>
			<uni-easyinput style="margin-top: 24rpx;border-radius: 16rpx;height: 90rpx;" v-model="leaveBoard.name"
				:placeholderStyle="placeholderStyle" placeholder="请输入您的称呼"></uni-easyinput>
			<view class="" style="font-weight: 600;font-size: 32rpx;color: #576260;margin-top: 32rpx;">
				联系方式 <span style="color: red;">*</span>
			</view>
			<uni-easyinput type="number" style="margin-top: 24rpx;border-radius: 16rpx;height: 90rpx;"
				v-model="leaveBoard.tel" :placeholderStyle="placeholderStyle"
				placeholder="请输入您的联系方式"></uni-easyinput>
			<view class="" style="font-weight: 600;font-size: 32rpx;color: #576260;margin-top: 32rpx;">
				问题描述
			</view>
			<u-input type="textarea" maxlength="500" border
				style="margin-top: 24rpx;border-radius: 16rpx;height: 253rpx;overflow: auto;font-size: 32rpx;"
				v-model="leaveBoard.content" :placeholderStyle="textareaStyle" placeholder="请输入问题描述" />
			<view class="align-center loginbtn justify-between">
				<button class="button fwbold" :style="{opacity:leaveBoard.tel.length>0?'1':'0.5'}"
					:disabled="leaveBoard.tel.length>0?false:true" type="primary"
					@click="leaveBoardAdd">立即提交</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		leaveBoardAdd,
	} from '@/api/api.js';
	export default{
		props:['title'],
		data(){
			return{
				placeholderStyle: "color:#7E8987;font-size:32rpx;font-weight: 300;",
				textareaStyle: "color:#7E8987;font-size:32rpx;font-weight: 300;",
				leaveBoard: {
					//姓名
					name: '',
					//留电方式
					tel: '',
					//内容
					content: ''
				},
			}
		},
		methods:{
			leaveBoardAdd() {
				// 正则表达式
				if (this.leaveBoard.tel != '') {
					if (!(/^1[3456789]\d{9}$/.test(this.leaveBoard.tel))) {
						this.$modal.msgError("手机号码格式错误，请重新输入")
						return false;
					}
				} else {
					this.$modal.msgError("请输入手机号码")
					return false;
				}
				leaveBoardAdd(this.leaveBoard).then(res => {
					if (res.code == 200) {
						this.$modal.msgSuccess("预约成功，客服人员将会与您联系。")
						this.leaveBoard = {
							name: '',
							tel: '',
							content: ''
						}
					} else if (res.code == 500) {
						// 重复提交！！！
						this.$modal.msgSuccess("已预约成功，请勿重复预约。")
						this.leaveBoard = {
							name: '',
							tel: '',
							content: ''
						}
					}
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .is-input-border {
		height: 90rpx;
		border-radius: 16rpx;
		border: 1rpx solid #D7DDDC;
	}
	
	::v-deep .uni-input-wrapper {
		font-size: 32rpx;
	}
	
	::v-deep .uni-easyinput__content-input {
		padding: 0 33rpx;
	}
	
	::v-deep .u-input__textarea {
		font-size: 32rpx;
		padding: 21rpx 0;
	}
	.formbox {
		box-sizing: border-box;
		padding-top: 32rpx;
		background: #fff;
		border-radius: 32rpx;
		margin-top: 16rpx;
	
		.title {
			position: relative;
			width: max-content;
			padding: 0 16rpx;
	
			.titleline {
				bottom: 0;
				left: 0;
				height: 16rpx;
				width: 100%;
				background: #00D9B2;
				border-radius: 50rpx;
				z-index: 1;
			}
		}
	
		.formcontent {
			box-sizing: border-box;
			padding: 32rpx;
	
			.loginbtn {
				margin-top: 32rpx;
	
				uni-button {
					border-radius: 98rpx;
					width: 100%;
				}
	
				uni-button:after {
					border: none;
				}
	
				.button {
					background-color: #00D9B2;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 36rpx;
	
				}
			}
		}
	}
</style>